<template>
<v-content>
  <v-flex>
    <v-toolbar flat color="white">
      <v-toolbar-title>My Share</v-toolbar-title>

      <v-divider class="mx-2" inset vertical></v-divider>
      <v-spacer></v-spacer>
    </v-toolbar>
    <v-data-table hide-actions :headers="headers" :items="fileInfo" class="elevation-1">
      <template slot="items" slot-scope="props">
        <td class="text-xs-left">{{ props.item.fileName }}</td>
        <td class="text-xs-left">{{ props.item.shareKey }}</td>
        <td class="text-xs-left">{{ props.item.extractCode }}</td>
        <td class="text-xs-left">{{ byteConvert(props.item.fileSize) }}</td>
        <td class="layout px-0">
          <v-icon small class="mr-2" @click="deleteThisShare(props.item)">mdi-delete</v-icon>
        </td>
      </template>
    </v-data-table>
  </v-flex>
</v-content>
</template>
<script>
export default {
    name:"myshare",
    data:()=>({
        headers: [
        { text: '文件名', value: '' ,sortable: false},
        { text: '分享码', value: '' ,sortable: false},
        { text: '提取码', value: '' ,sortable: false},
        { text: '文件大小', value: '' ,sortable: false},
        { text: '管理', value: '', sortable: false }
        ],
        fileInfo:[],
    }),
    created(){
      this.init();
    },

    methods:{
      init(){
        this.$http.post("/share/getShareFileList/"+sessionStorage.getItem("username")).then(res=>{
          this.fileInfo=res.data;
        });
     }
     ,
     deleteThisShare(item){
       alert(item.originFileId);
       let fd=new FormData();
       fd.append("originFileId",item.originFileId);
       fd.append("shareKey",item.shareKey);
       this.$http.post("/share/delShareFile/"+sessionStorage.getItem("username"),fd).then(res=>{
         alert(res.data);
         this.init();
       });
     }
    ,    
    byteConvert :function(bytes) {
    if (isNaN(bytes)) {
        return '';
    }
    var symbols = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
    var exp = Math.floor(Math.log(bytes)/Math.log(2));
    if (exp < 1) {
        exp = 0;
    }
    var i = Math.floor(exp / 10);
    bytes = bytes / Math.pow(2, 10 * i);

    if (bytes.toString().length > bytes.toFixed(2).toString().length) {
        bytes = bytes.toFixed(2);
    }
    return bytes + ' ' + symbols[i];
}
    
    }
};
</script>
